#include <iostream>
#include <cstdio>
#include <vector>
#include <functional>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>

void PrintPending(sigset_t &pending)
{
    printf("我是一个进程(%d),pending: ",getpid());
    for(int signo = 31; signo >= 1; signo--)
    {
        if(sigismember(&pending,signo))
        {
            std::cout<<"1";
        }
        else
        {
            std::cout<<"0";
        }
    }
    std::cout<<std::endl;
}

int main()
{
    //1.屏蔽2号信号
    sigset_t block, oblock;
    sigemptyset(&block);
    sigemptyset(&oblock);

    sigaddset(&block,SIGINT);
    
    int n = sigprocmask(SIG_SETMASK,&block,&oblock);
    (void)n;

    while(true)
    {
        //2.获取信号
        sigset_t pending;
        int m = sigpending(&pending);

        PrintPending(pending);
        sleep(1);
    }
    return 0;
}
